{
 "cells": [
  {
   "cell_type": "raw",
   "metadata": {
    "raw_mimetype": "text/restructuredtext"
   },
   "source": [
    ".. _nb_heat:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Heatmap\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For getting an idea of the distribution of values, heatmaps can be used.\n",
    "\n",
    "Let us visualize some test data:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "\n",
    "np.random.seed(1234)\n",
    "F = np.random.random((4, 6))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "A simple heatmap can be created by:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "from pymoo.visualization.heatmap import Heatmap\n",
    "Heatmap().add(F).show()"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "By default, larger values are represented with wight and smaller values with the corresponding color:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "Heatmap(bounds=[0,1]).add(np.ones((1, 6))).show() "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This behavior can be changed by setting `reverse` to False."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "Heatmap(bounds=[0,1],reverse=False).add(np.ones((1, 6))).show() "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The plot can be further customized by supplying a title, labels, and by using the plotting directives from matplotlib. Also, colors can be changed:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "plot = Heatmap(title=(\"Optimization\", {'pad': 15}),\n",
    "               cmap=\"Oranges_r\",\n",
    "               y_labels=[\"Solution A\", \"Solution B\", \"Solution C\", \"Solution D\"],\n",
    "               labels=[\"profit\", \"cost\", \"sustainability\", \"environment\", \"satisfaction\", \"time\"])\n",
    "plot.add(F)\n",
    "plot.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Moreover, the values can be sorted lexicographically by objective(s) - and by default, the selected objective is inserted in position 0 of the range of objectives. Also, boundaries can be changed. Otherwise, it is scaled according to the smallest and largest values supplied."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "F = np.random.random((30, 6))\n",
    "\n",
    "plot = Heatmap(figsize=(10,30),\n",
    "               bound=[0,1],\n",
    "               order_by_objectives=0,\n",
    "               y_labels=None,\n",
    "               labels=[\"profit\", \"cost\", \"sustainability\", \"environment\", \"satisfaction\", \"time\"],\n",
    "               cmap=\"Greens_r\")\n",
    "\n",
    "plot.add(F, aspect=0.2)\n",
    "plot.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### API"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {
    "raw_mimetype": "text/restructuredtext"
   },
   "source": [
    ".. autoclass:: pymoo.visualization.heatmap.Heatmap\n",
    "    :noindex:"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
